* Regressions for Tables A.4, A.6, A.8, and B.4.
set matsize 11000

label var ratio "log(SI)"
label var ratio2 "log(SI)"
label var ratioC2 "log(SI_cons)"

* Table A4 (controls time trends)
xi: quietly regress ratio deva i.ccode i.year, r // year FE
estimates store One
xi: quietly regress ratio deva i.ccode year, r // linear trend
estimates store Two
xi: quietly regress ratio deva i.ccode year year2, r // quadratic trend
estimates store Three
xi: quietly regress ratio deva i.ccode year year80 year90 year00, r // decadal-specific, linear
estimates store Four
xi: quietly regress ratio deva i.ccode*year, r // country-specific linear trend
estimates store Five
xi: quietly regress ratio deva i.ccode*year i.ccode*year2, r // country-specific quadratic trend
estimates store Six
xi: quietly regress ratio deva i.ccode*year i.country*year80 i.country*year90 i.country*year00 i.country , r // decadal-specific, country-specific linear
estimates store Seven
xi: quietly regress ratio deva i.ccode i.year i.year*D i.year*Recent, r // year FE, interacted with treated
estimates store Eight
xi: quietly regress ratio deva i.ccode year yearD yearJ year80 year80D year80J year90 year90D year90J year00 year00D year00J, r // decadal-spec, treated
estimates store Nine
esttab One Two Three Four Five Six Seven Eight Nine, keep(deva) b(%9.3f) se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01)
esttab One Two Three Four Five Six Seven Eight Nine using "`1'/TableA4.csv", label keep(deva) b(%9.2f) se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01) replace
	
if `2'==1 { // existence of pre-trends
capture drop ratiopFEdiff
xi: quietly regress ratio i.ccode i.year, r // year FE
capture predict ratiopFE, resid
xi: quietly regress ratio i.ccode year, r // linear trend
capture predict ratiopLinear, resid
xi: quietly regress ratio i.ccode year year2, r // quadratic trend
capture predict ratiopQuad, resid
xi: quietly regress ratio i.ccode year year80 year90 year00, r // decadal-specific, linear
capture predict ratiopLinearDecad, resid
xi: quietly regress ratio i.ccode*year, r // country-specific linear trend
capture predict ratiop2, resid
xi: quietly regress ratio i.ccode*year i.ccode*year2, r // country-specific quadratic trend
capture predict ratiopQ2, resid
xi: quietly regress ratio i.ccode*year i.country*year80 i.country*year90 i.country*year00 i.country , r // decadal-specific, country-specific linear
capture predict ratiopD, resid
xi: quietly regress ratio i.ccode i.year i.year*D i.year*Recent, r // year FE, interacted with treated
capture predict ratiopFEdiff, resid
xi: quietly regress ratio i.ccode year yearD yearJ year80 year80D year80J year90 year90D year90J year00 year00D year00J, r // decadal-spec, treated
capture predict ratiopLinearDecaddiff, resid
estimates clear
preserve
	keep if D==1 // at least one deva
	eststo: quietly regress ratiopFE year
	eststo: quietly regress ratiopLinear year
	eststo: quietly regress ratiopQuad year
	eststo: quietly  regress ratiopLinearDecad year
	eststo: quietly  regress ratiop2 year
	eststo: quietly  regress ratiopQ2 year
	eststo: quietly  regress ratiopD year
	eststo: quietly  regress ratiopFEdiff year
	eststo: quietly  regress ratiopLinearDecaddiff year
restore
esttab using "`1'/TableB4_A.csv",  se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01)  label nocon replace
estimates clear
preserve
	keep if Recent==1 // at least one deva after 95
	eststo: quietly regress ratiopFE year
	eststo: quietly regress ratiopLinear year
	eststo: quietly regress ratiopQuad year
	eststo: quietly  regress ratiopLinearDecad year
	eststo: quietly  regress ratiop2 year
	eststo: quietly  regress ratiopQ2 year
	eststo: quietly  regress ratiopD year
	eststo: quietly  regress ratiopFEdiff year
	eststo: quietly  regress ratiopLinearDecaddiff year
restore
esttab using "`1'/TableB4_B.csv",  se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01)  label nocon replace
}

* Table A8 (controls for confounding factors)
label var logtau "ln(1+tariffs)"
label var restru "Restructuring"
label var financial "Banking"
label var lRGDP "log(RGDP)"
label var default "Default"

xi: quietly regress ratio deva i.ccode i.year i.year*D i.year*Recent, r // year FE, differential
estimates store One
xi: quietly regress ratio deva lRGDP i.ccode i.year i.year*D i.year*Recent, r
estimates store Three
xi: quietly regress ratio deva financial default restru i.ccode i.year i.year*D i.year*Recent, r
estimates store Four
xi: quietly regress ratio deva lRGDP financial default restru i.ccode i.year i.year*D i.year*Recent, r
estimates store Five
xi: quietly regress ratio deva logtau lRGDP financial default restru i.ccode i.year i.year*D i.year*Recent, r
estimates store Six
esttab One Three Four Five Six, keep(deva logtau lRGDP financial default restru ) b(%9.2f) se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01)
esttab One Three Four Five Six using "`1'/TableA8.csv", label keep(deva logtau lRGDP financial default restru ) b(%9.2f) se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01) replace

* Table A6 (final good import share)
preserve
	keep if year>=1995
	di ("OECD/WIOD Post 1995")
	di ("Inputs")
	xi: quietly regress ratio2 deva i.ccode i.year, r // year FE
	estimates store One
	xi: quietly regress ratio2 deva i.ccode year, r // linear trend
	estimates store Two
	xi: quietly regress ratio2 deva i.ccode year year2, r // quadratic trend
	estimates store Three
	xi: quietly regress ratio2 deva i.ccode year year80 year90 year00, r // decadal-specific, linear
	estimates store Four
	xi: quietly regress ratio2 deva i.ccode*year, r // country-specific linear trend
	estimates store Five
	xi: quietly regress ratio2 deva i.ccode*year i.ccode*year2, r // country-specific quadratic trend
	estimates store Six
	xi: quietly regress ratio2 deva i.ccode*year i.country*year80 i.country*year90 i.country*year00 i.country , r // decadal-specific, country-specific linear
	estimates store Seven
	xi: quietly regress ratio2 deva i.ccode i.year i.year*D i.year*Recent, r // year FE, interacted with treated
    estimates store Eight
	xi: quietly regress ratio2 deva i.ccode year yearD yearJ year80 year80D year80J year90 year90D year90J year00 year00D year00J, r // decadal-spec, treated
	estimates store Nine
	esttab One Two Three Four Five Six Seven Eight Nine, keep(deva) b(%9.2f) se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01)
	esttab One Two Three Four Five Six Seven Eight Nine using "`1'/TableA6_B.csv", label keep(deva) b(%9.2f) se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01) replace

	di ("Consumption Import Share")
	xi: quietly regress ratioC2 deva i.ccode i.year, r // year FE
	estimates store One
	xi: quietly regress ratioC2 deva i.ccode year, r // linear trend
	estimates store Two
	xi: quietly regress ratioC2 deva i.ccode year year2, r // quadratic trend
	estimates store Three
	xi: quietly regress ratioC2 deva i.ccode year year80 year90 year00, r // decadal-specific, linear
	estimates store Four
	xi: quietly regress ratioC2 deva i.ccode*year, r // country-specific linear trend
	estimates store Five
	xi: quietly regress ratioC2 deva i.ccode*year i.ccode*year2, r // country-specific quadratic trend
	estimates store Six
	xi: quietly regress ratioC2 deva i.ccode*year i.country*year80 i.country*year90 i.country*year00 i.country , r // decadal-specific, country-specific linear
	estimates store Seven
	xi: quietly regress ratioC2 deva i.ccode i.year i.year*Recent, r // year FE, interacted with treated
	estimates store Eight
	xi: quietly regress ratioC2 deva i.ccode year yearJ year80 year80J year90 year90J year00 year00J, r // decadal-spec, treated
	estimates store Nine
	esttab One Two Three Four Five Six Seven Eight Nine, keep(deva) b(%9.2f) se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01)
	esttab One Two Three Four Five Six Seven Eight Nine using "`1'/TableA6_A.csv", label keep(deva) b(%9.2f) se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01) replace
restore
